# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-ssl
pkgver=0.7.0
pkgrel=0
pkgdesc="Bindings for OpenSSL"
url="https://github.com/savonet/ocaml-ssl"
arch="all !riscv64 !loongarch64" # ocaml
license="LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	openssl-dev
	"
makedepends="
	$depends_dev
	dune
	dune-configurator
	ocaml
	"
checkdepends="ocaml-alcotest-dev"
subpackages="$pkgname-dev"
source="https://github.com/savonet/ocaml-ssl/archive/refs/tags/v$pkgver/ocaml-ssl-$pkgver.tar.gz"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --release --verbose
}

check() {
	# ssl_sock test sometimes requires multiple retries to succeed
	# dune runtest re-runs the tests that failed only, not all tests
	local i; for i in $(seq 0 3); do
		[ $i -eq 0 ] || msg "Retrying ($i/3)..."
		dune runtest --build-dir=.testenv --verbose && return 0
		sleep 1
	done
	return 1
}

package() {
	dune install --destdir="$pkgdir" --docdir=/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
969c4d64828449a49bdef26ca5f8faa72d2fe2a2304ccbf589a3ff097c2bf8ae9eb83ae1c90216f6b4d6f359e462ea47e0106a7386e26848d14910138fcb07f8  ocaml-ssl-0.7.0.tar.gz
"
